/*
 * IPDL - Iterated Prisoner's Dilemma Library
 * Copyright (C) by Tomasz Kaczanowski
 * tkaczano at poczta dot onet dot pl
 * http://kaczanowscy.pl/ipdl
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package pl.kaczanowscy.tomek.ipdl;

import java.util.HashMap;
import java.util.Map;

import pl.kaczanowscy.tomek.ipdl.enums.Move;

/**
 * Implementation of {@link RoundResult} interface. Immutable (not really as it
 * doesn't clone returned moves etc).
 * 
 * @author Tomasz Kaczanowski
 */
public final class RoundResultImpl implements RoundResult {

	private final Map<Strategy, Integer> payoffs;
	private final Map<Strategy, Integer> opponentPayoffs;
	private final Map<Strategy, Move> moves;
	private final Map<Strategy, Move> opponentMoves;

	public RoundResultImpl(Strategy strategyA, int payoffA, Move moveA,
			Strategy strategyB, int payoffB, Move moveB) {
		payoffs = new HashMap<Strategy, Integer>(2);
		payoffs.put(strategyA, payoffA);
		payoffs.put(strategyB, payoffB);

		opponentPayoffs = new HashMap<Strategy, Integer>(2);
		opponentPayoffs.put(strategyA, payoffB);
		opponentPayoffs.put(strategyB, payoffA);

		moves = new HashMap<Strategy, Move>(2);
		moves.put(strategyA, moveA);
		moves.put(strategyB, moveB);

		opponentMoves = new HashMap<Strategy, Move>(2);
		opponentMoves.put(strategyA, moveB);
		opponentMoves.put(strategyB, moveA);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * pl.kaczanowscy.tomek.ipdl.RoundResult#getMove(pl.kaczanowscy.tomek.ipdl
	 * .Strategy)
	 */
	public Move getMove(Strategy strategy) {
		return moves.get(strategy);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * pl.kaczanowscy.tomek.ipdl.RoundResult#getOpponentMove(pl.kaczanowscy.
	 * tomek.ipdl.Strategy)
	 */
	public Move getOpponentMove(Strategy strategy) {
		return opponentMoves.get(strategy);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * pl.kaczanowscy.tomek.ipdl.RoundResult#getPayoff(pl.kaczanowscy.tomek.
	 * ipdl.Strategy)
	 */
	public int getPayoff(Strategy strategy) {
		return payoffs.get(strategy);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * pl.kaczanowscy.tomek.ipdl.RoundResult#getOpponentPayoff(pl.kaczanowscy
	 * .tomek.ipdl.Strategy)
	 */
	public int getOpponentPayoff(Strategy strategy) {
		return opponentPayoffs.get(strategy);
	}

}
